package es.capgemini.extjsplugin.wizard;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

import es.capgemini.extjsplugin.ui.ComponentSelectionPanel;

public class ComponentSelectionPage extends WizardPage implements Listener {
	ComponentSelectionPanel panel;
	protected ComponentSelectionPage(String pageName) {
		super(pageName);
		setTitle("Componentes");
		setDescription("Seleccionar los componentes a generar");
	}

	@Override
	public void createControl(Composite parent) {
		panel=new ComponentSelectionPanel(parent, SWT.EMBEDDED);
		setControl(panel);
		addListeners();
		setPageComplete(true);
	}	
	public void saveDataToModel(){
		 // Gets the model
		GeneratorWizard wizard = (GeneratorWizard)getWizard();
		GeneratorWizardModel model = wizard.model;
		model.setDao(panel.getChkDao().getSelection());
		model.setAltaEdicionForm(panel.getChkForm().getSelection());
		model.setDto(panel.getChkDto().getSelection());
		model.setEditarEliminar(panel.getChkButtons().getSelection());
		model.setFlow(panel.getChkFlows().getSelection());
		model.setListado(panel.getChkListado().getSelection());
		model.setManager(panel.getChkManager().getSelection());
		
	}
	private void addListeners(){
		panel.getChkDao().addListener(SWT.Selection, this);
		panel.getChkButtons().addListener(SWT.Selection, this);
		panel.getChkDto().addListener(SWT.Selection, this);
		panel.getChkFlows().addListener(SWT.Selection, this);
		panel.getChkForm().addListener(SWT.Selection, this);
		panel.getChkListado().addListener(SWT.Selection, this);
		panel.getChkManager().addListener(SWT.Selection, this);
		
	}

	@Override
	public void handleEvent(Event evt) {
		
		//setPageComplete(panel.canFinish());
		
		
		getWizard().getContainer().updateButtons();
	};
	public boolean canFinish(){
		return panel.canFinish();
	}

}
